home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue37 / ramirez.cylcalc < prev    next >
Encoding:
Text File  |  2002-08-14  |  781 b   |  51 lines

  1. /*
  2.     cylcalc
  3.     -------
  4.     Calculate the cylinders needed to format X MB on the hard drive.
  5.  
  6.     Gilbert Ramirez
  7.     Technical Services
  8.     University Health System
  9.  
  10.     $Id: ramirez.cylcalc,v 1.1.1.1 2002/08/14 22:27:25 dan Exp $
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.     int        megs;
  20.     int        heads;
  21.     int        sectors;
  22.     int        bytes;
  23.  
  24.     int        cyl;
  25.     int        calc_bytes;
  26.  
  27.     if (argc != 4) {
  28.         fprintf(stderr, "\nusage: %s megabytes heads sectors\n"
  29.             "\tcalculates cylinders needed for such a format.\n",
  30.             argv[0]);
  31.         exit(-1);
  32.     }
  33.  
  34.     megs = atoi(argv[1]);
  35.     heads = atoi(argv[2]);
  36.     sectors = atoi(argv[3]);
  37.  
  38.  
  39.     bytes = megs * 1024 * 1024;
  40.     cyl = 0;
  41.  
  42.     do {
  43.         cyl++;
  44.         calc_bytes = heads * sectors * 512 * cyl;
  45.     } while (calc_bytes < bytes);
  46.  
  47.     printf("%d\n", cyl);
  48.  
  49.     return 0;
  50. }
  51.